<?php
/**
 * 常用类
 * 
 * @author ShuangYa
 * @package TBSign
 * @category Library
 * @link http://www.roadlogica.cn/
 */

namespace tbsign\libs;
use \Sy;

class Common {
	/**
	 * 判断是否为POST请求
	 * @access public
	 * @return boolean
	 */
	public static function isPost() {
		return ($_SERVER['REQUEST_METHOD'] === 'POST') ? TRUE : FALSE;
	}
	/**
	 * 判断是否为PJAX请求
	 * @access public
	 * @return boolean
	 */
	public static function isPjax() {
		return isset($_SERVER['HTTP_X_PJAX']);
	}
	/**
	 * 判断是否为AJAX请求
	 * @access public
	 * @return boolean
	 */
	public static function isAjax() {
		return (isset($_SERVER['HTTP_X_AJAX']) || isset($_REQUEST['ajax']));
	}
	/**
	 * 显示JSON返回结果
	 * @access public
	 * @param array $arr
	 */
	public static function showAjax($arr = []) {
		if (isset($arr['error'])) {
			$arr['success'] = 0;
		} else {
			$arr['success'] = 1;
		}
		Sy::setMimeType('json');
		echo json_encode($arr);
		exit;
	}
}